//
//  TSNetworkTools.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/10/21.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import Moya

public enum TMSNetworkTools {
    
    /** 登录、注册 */
    case login(username:String, verifyCode:String, password:String, capid:String)
    case register(username:String , password:String, repassword:String)
    
    /** 获取验证码 */
    case getVertifyCode
    
    /** 首页公告列表 */
    case getNotice
    /** 首页轮播 */
    case getBanner
    
    /** 投注 */
    case getInvest(qihao:String, jizhu:String, qufen:String, one:String, two:String, three:String, four:String)
    
    /** 获取赛车彩票数据 */
    case getRacingInfo
    /** 获取游艇彩票数据 */
    case getYachtInfo
    /** 获取赛车开奖数据 */
    case getRacingResultInfo
    /** 获取游艇开奖数据 */
    case getYachtResultInfo
    
    /** 银行卡列表 */
    case getCardList
    /** 绑定银行卡 */
    case bindCard(bankname:String, bankusername:String, banknum:String, bankadress:String, bankpwd:String)
    
//MARK: 充值
    /** 获取USDT充值信息 */
    case rechargeUsdt
    /** 充值 */
    case requestForRecharge(money:String, ustdname:String)
    
//MARK: 银行卡提现
    case withdrawProfit(money:String, bankpwd:String)
    case withdrawGain(money:String, bankpwd:String)
    case withdrawStore(money:String, bankpwd:String)
    
//MARK: USDT提现
    case withdrawUSDTProfit(ustd:String, usdt_adress:String, bankpwd:String)
    case withdrawUSDTGain(ustd:String, usdt_adress:String, bankpwd:String)
    case withdrawUSDTStore(ustd:String, usdt_adress:String, bankpwd:String)
    
//MARK: 额度转换
    /** 额度转换配置信息 */
    case getconvertInfo
    /** 中心钱包转金币 */
    case convertCashToCoin(money:String)
    /** 金币钱包转中心 */
    case convertCoinToCash(money:String)
    /** 收益钱包转盈利 */
    case convertProfitToGain(money:String)
    /** 盈利钱包转中心 */
    case convertGainToCash(money:String)
    
    /** 修改登录密码 */
    case reverseLoginPassword(oldpwd:String, password:String, repassword:String)
    /** 修改提现密码 */
    case reverseCashPassword(oldpwd:String, password:String, repassword:String)

    /** 升级流水 */
    case getUpgradeInfo
    /** 获取用户信息 */
    case getUserInfo
    /** 个人中心公告 */
    case noticeData
    
    /** 投注记录 */
    case getInvsetRecord(type:String?)
    /** 投注记录过滤 */
    case getInvsetFilterRecord(status:String, qufen:String, start_time:String, end_time:String)
    
    /** 充值、提现、账变明细记录 */
    case getRecord(status:String)
    
    /** 撤单 */
    case revokeOrder(id:String)
    
    /** 我的团队 -- 我的下级 */
    case getMyteam
    /** 我的团队 -- 代理级别 */
    case getAgentLevel
}

extension TMSNetworkTools:TargetType {
    
    public var baseURL:URL {
        return URL(string: "http://ai.888cjc.com/api/")!
    }

    public var path: String {
        switch self {
        case .login :
            return "login/login"
            
        case .register :
            return "login/register"
            
        case .getVertifyCode:
            return "login/showcap"
            
        case .getUpgradeInfo:
            return "user/shengji_bili"
            
        case .getUserInfo :
            return "user/user"
            
        case .getNotice :
            return "show/notice"

        case .getBanner:
            return "show/banner"
            
        case .getInvest:
            return "payxyft/index"
            
        case .getRacingInfo:
            return "pk/index"
                
        case .getYachtInfo:
            return "xyft/index"
            
        case .getRacingResultInfo:
            return "pk/showlist"
                
        case .getYachtResultInfo:
            return "xyft/showlist"
            
        case .getCardList:
            return "bank/showbank"
        
        case .bindCard:
            return "bank/addbank"
            
        case .rechargeUsdt:
            return "conf/ustd"
        
        case.requestForRecharge:
            return "chongzhi/index"
            
        case .withdrawProfit:
            return "tixian/rmbyingli"
        case .withdrawGain:
            return "tixian/rmbshouyi"
        case .withdrawStore:
            return "tixian/rmbzhongxin"
            
        case .withdrawUSDTProfit:
            return "tixian/usdtshouyi"
        case .withdrawUSDTGain:
            return "tixian/usdtyingli"
        case .withdrawUSDTStore:
            return "tixian/usdtzhongxin"
        
        case .reverseLoginPassword:
            return "login/editpwd"
        case .reverseCashPassword:
            return "pwd/edittxpwd"

        case .noticeData:
            return "show/gonggao"
        
        case .getInvsetRecord:
            return "glist/xypklist"
        
        case .getInvsetFilterRecord:
            return "glist/shaixuan"
            
        case .convertCashToCoin:
            return "chongzhi/zjinbi"
        case .convertCoinToCash:
            return "chongzhi/jin_zhong"
        case .convertProfitToGain:
            return "chongzhi/shouyi_yingli"
        case .convertGainToCash:
            return "chongzhi/yingli_zhongxin"
        case .getconvertInfo:
            return "chongzhi/conf"
            
        case .getRecord:
            return "chongzhi/showlist"
            
        case .revokeOrder:
            return "payxyft/chedan"
            
        case .getMyteam:
            return "item/index"
            
        case .getAgentLevel:
            return "conf/index"
        }
        
    }

    public var method: Moya.Method {
        switch self {
        case .login, .register, .getVertifyCode, .getUserInfo, .getBanner, .getRacingInfo, .getYachtInfo, .getCardList, .bindCard, .reverseLoginPassword, .reverseCashPassword, .noticeData, .getInvsetFilterRecord, .convertCashToCoin, .convertCoinToCash, .convertProfitToGain, .convertGainToCash, .getconvertInfo, .getInvest, .rechargeUsdt, .requestForRecharge, .withdrawProfit, .withdrawGain, .withdrawStore, .withdrawUSDTProfit, .withdrawUSDTGain, .withdrawUSDTStore, .getRecord, .revokeOrder, .getMyteam, .getAgentLevel:
            return .post
            
        case .getNotice, .getInvsetRecord, .getRacingResultInfo, .getYachtResultInfo, .getUpgradeInfo:
            return .get
        }
    }

    //请求任务事件，带上参数
    public var task: Task {
        switch self {
            
        case .login(let username, let verifyCode, let password, let capid) :
//            return .requestData(jsonToData(jsonDic: ["username":username, "verifyCode":verifyCode, "password":password])!) //参数放在HttpBody中
            return .requestParameters(parameters: ["username":username, "verifyCode":verifyCode, "password":password, "capid":capid], encoding: URLEncoding.default)

//        case .getNotice:
//        let parmeters = [String : Any]()
//        return .requestParameters(parameters: parmeters, encoding: URLEncoding.default) //参数放在请求的url中
        case .register(let username, let password, let repassword):
            let param = ["username":username, "password":password, "repassword":repassword, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .getInvsetRecord(let type):
            var param = ["token":TSLoginManager.shared.token!]
            if type?.count ?? 0 > 0 {
                param["type"] = type
            }
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .getVertifyCode, .getUserInfo, .getUpgradeInfo, .getNotice, .getBanner, .getRacingInfo, .getYachtInfo, .getCardList, .noticeData, .getRacingResultInfo, .getYachtResultInfo, .rechargeUsdt, .getconvertInfo, .getMyteam, .getAgentLevel:
            return .requestParameters(parameters: ["token":TSLoginManager.shared.token!], encoding: URLEncoding.default) //参数放在请求的url中
        
        case .bindCard(let bankname, let bankusername, let banknum, let bankadress, let bankpwd):
            let param = ["bankname":bankname, "bankusername":bankusername, "banknum":banknum, "bankadress":bankadress, "bankpwd":bankpwd, "token":TSLoginManager.shared.token!]
        return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .reverseLoginPassword(let oldpwd, let password, let repassword), .reverseCashPassword(let oldpwd, let password, let repassword):
            
            let param = ["oldpwd":oldpwd, "password":password, "repassword":repassword, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .getInvsetFilterRecord(let status, let qufen, let start_time, let end_time):
            let param = ["status":status, "qufen":qufen, "start_time":start_time, "end_time":end_time, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .convertCashToCoin(let money), .convertCoinToCash(let money), .convertProfitToGain(let money), .convertGainToCash(let money):
            let param = ["money":money,"token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .getInvest(let qihao, let jizhu, let qufen, let one, let two, let three, let four):
            let param = ["qihao":qihao, "jizhu":jizhu, "qufen":qufen, "one":one, "two":two, "three":three, "four":four, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .requestForRecharge(let money, let ustdname):
            let param = ["money":money, "ustdname":ustdname, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .withdrawProfit(let money, let bankpwd), .withdrawGain(let money, let bankpwd), .withdrawStore(let money, let bankpwd):
            let param = ["money":money, "bankpwd":bankpwd, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
        
        case .withdrawUSDTProfit(let ustd, let usdt_adress, let bankpwd), .withdrawUSDTGain(let ustd, let usdt_adress, let bankpwd), .withdrawUSDTStore(let ustd, let usdt_adress, let bankpwd):
            
            let param = ["ustd":ustd, "usdt_adress":usdt_adress, "bankpwd":bankpwd, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .getRecord(let status):
            let param = ["status":status, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            
        case .revokeOrder(let id):
            let param = ["id":id, "token":TSLoginManager.shared.token!]
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
            

//        case .getBanner, .getUserInfo, .getNotice:
////            return .requestData(jsonToData(jsonDic: ["token":TSLoginManager.shared._usermodel?.token ?? ""])!)
//            let param = ["token":TSLoginManager.shared._usermodel?.token ?? ""]
//            return .requestData(jsonToData(jsonDic: param) ?? Data())
        }
    }

    //是否执行Alamofire验证
    //    public var validate: Bool {
    //        return false
    //    }

    //验证方式
    public var validationType: ValidationType {
        return .none
    }

    //这个就是做单元测试模拟的数据，只会在单元测试文件中有作用
    public var sampleData: Data {
        return Data(base64Encoded: "just for test")!
    }

    //请求头
    public var headers: [String : String]? {
        
        return nil
//        return ["content-Type" : "application/json;charset=UTF-8"]
//        switch self {
//        case .login:
//            let header = ["Content-Type" : "application/json"]
//            return header
//        default:
//            return nil
//        }
    }
    
    
    

}

